home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / M2PROTOS.ZIP / PATHFIND.DEF < prev    next >
Encoding:
Modula Definition  |  1991-02-09  |  2.4 KB  |  76 lines

  1. (*%F _fdata *)
  2. (*# call(seg_name => null) *)
  3. (*%E *)
  4. (*# module(implementation=>off) *)
  5. (*# data(seg_name => null) *)
  6. (*# call(o_a_copy => off) *)
  7. (*# check(stack=>off,
  8.           index=>off,
  9.           range=>off,
  10.           overflow=>off,
  11.           nil_ptr=>off) *)
  12. DEFINITION MODULE PathFind;
  13.  
  14. (* Source code for JPI TopSpeed Modula-2 by
  15.  
  16.     Carl Neiburger
  17.     169 N. 25th St.
  18.     San Jose, Calif. 95116
  19.  
  20.     CompuServe No. 72336,2257
  21.  
  22. *)
  23.  
  24. FROM FioAsm IMPORT PathStr, PathTail; (* Same as JPI's FIO PathStr, PathTail *)
  25.  
  26. TYPE
  27.     FilePtr = POINTER TO FileRec;
  28.  
  29.     FileRec = RECORD
  30.          Name: PathStr;
  31.          Next: FilePtr
  32.     END;
  33.  
  34. PROCEDURE FindEnvStr( target : ARRAY OF CHAR; VAR string: ARRAY OF CHAR );
  35.  
  36. (* Finds a specified string in the environment and returns its arguments.
  37.    For example, if you have set "path = e:\;e:\utils" then
  38.    FindEnvStr( 'PATH', path ) will return with the variable
  39.    path set equal to "E:\;E:\UTILS"
  40.    The returned string will always be in upper case letters. 
  41.    If target cannot be found, string will be empty. *)
  42.  
  43.  
  44. PROCEDURE FindPath(PathName,
  45.                    TargetName: ARRAY OF CHAR;
  46.                VAR TargetPath: ARRAY OF CHAR): BOOLEAN;
  47.  
  48. (* Attempts to find the file name TargetName given an environment string,
  49.    PathName. For example, if PATHFIND.MOD is in the F:\M2 directory, and you 
  50.    have set the PATH string accordingly, 
  51.    FindPath("PATH", "PATHFIND.MOD", filename) will return TRUE and 
  52.    TargetPath will equal "F:\M2\PATHFIND.MOD" *)
  53.  
  54. PROCEDURE ParsePath(VAR Path: PathStr; 
  55.                     VAR FileName: PathTail): BOOLEAN;
  56.  
  57. (* Parses the string Path into a valid directory path and a file name.
  58.  
  59.    You MUST INITIALIZE Path -- the string to parse -- AND a default FileName,
  60.    to be returned if the path does not include a file name.  FileName can be 
  61.    '' to return the path only, '*.*' for a wildcard reference to all files
  62.    or some other default name.  The path will be returned without the final 
  63.    backslash, so the root directory appears as 'D:'.
  64.  
  65.    If the path is not valid, ParsePath will return FALSE.
  66. *)
  67.  
  68. PROCEDURE FileTree ( Path: PathStr ): FilePtr;
  69. (* Returns a linked list of all files matching Path. If a file mask is not 
  70.    specified, returns all files in directory. *)
  71.  
  72. PROCEDURE UnFileTree ( VAR Ptr : FilePtr );
  73. (* Disposes of a file tree, returning the memory to the heap *)
  74.  
  75. END PathFind.
  76.